<?php
require_once("../control/config.class.php");
require_once("../control/utilidades.class.php");

	$executar = new Conexao;
	$utilidades = new Utilidades;

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

<script src="calendario/src/js/jscal2.js"></script>
    <script src="calendario/src/js/lang/pt.js"></script>
    <link rel="stylesheet" type="text/css" href="calendario/src/css/jscal2.css" />
    <link rel="stylesheet" type="text/css" href="calendario/src/css/border-radius.css" />
    <link rel="stylesheet" type="text/css" href="calendario/src/css/steel/steel.css" />

<style type="text/css">
.titulo_cad {
	font-family: Verdana, Geneva, sans-serif;
	font-size: 16px;
	font-weight: bold;
	color: #666;
}
.tabela{
	font-family: Verdana, Geneva, sans-serif;
	font-size: 12px;
	font-weight: bold;
	color: #666;
}
.tabela_titulo{
	font-family: Verdana, Geneva, sans-serif;
	font-size: 12px;
	font-weight: bold;
	color: #333;
}
.tabela_semana{
	font-family: Verdana, Geneva, sans-serif;
	font-size: 12px;
	font-weight: bold;
	color: #006;
}
.tabela_dia_mes{
	font-family: Verdana, Geneva, sans-serif;
	font-size: 12px;
	font-weight: bold;
	color: #00C;
}
a:link {
	color: #000;
}
a:visited {
	color: #000;
}
a:hover {
	color: #666;
}
a:active {
	color: #000;
}
.titulo_tabela {font-family: Verdana, Geneva, sans-serif;
	font-size: 12px;
	color: #333;
	font-weight: bold;
}
.link {
	font-family: Verdana, Geneva, sans-serif;
	font-size: 12px;
	color: #CCC;
}
</style>

</head>

<script language="JavaScript">
	Resposta = new Array(24)
	Quant = 1
	Anterior = 0
	Tamanho = 0
	Repostas [1] = 0;
	
	
	function busca()
	{
		w = open ("pesquisar_usuarios.php?id_uni=<?php echo $_GET['id_uni']; ?>","winLov","Scrollbars=yes, resizable=no, width=700, height=550");
		if (w.opener == null){
			w.opener = self;
		}
		w.focus();
				
	}//fecha a function busca
</script>

<script language="javascript">
function imprimir(data1,data2,codigo_user,codigo_uni) {
  window.open("../view/imprimir_log.php?data_ini=" +data1+"&data_fim="+data2+"&id_user="+codigo_user+"&id_uni="+codigo_uni,"","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,WIDTH=950,HEIGHT=700,top=50,left=50");
}
</script>

<body>
<form id="form1" name="form1" method="post" action="?path=rel_log&id_uni=<?php echo $_GET['id_uni']; ?>">
  <table width="900" border="0" align="center">
    <tr>
      <td align="left"><table width="260" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="60" align="right"><a href="?path=rel&id_uni=<?php echo $_GET['id_uni']; ?>&carregar" title="Voltar"><img src="../img/atras.png" alt="" width="48" height="48" border="0" /></a></td>
          <td width="184"><a href="?path=rel&id_uni=<?php echo $_GET['id_uni']; ?>&carregar" class="titulo_cad"><span class="titulo_cad">&nbsp;Voltar</span></a></td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td class="titulo_cad">&nbsp;&nbsp;Relat&oacute;rio de Log</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
    </tr>
        <?php
		$sql="Select * from unidades_educacionais where codigo=".$_GET['id_uni']." ; ";
		$resultado=$executar->execSQL($sql);
		if($resultado){
			$nome=mysql_result($resultado,0,"nome");
		}
	?>
    <tr>
      <td align="left" class="tabela_semana">Campus/Unidade : <?php echo $nome; ?></td>
    </tr>
    <tr>
      <td><table width="100%" border="0">

        <tr>
          <td align="right" class="tabela_titulo">&nbsp;</td>
          <td align="left">&nbsp;</td>
          <td align="left">&nbsp;</td>
          <td align="center">&nbsp;</td>
        </tr>
        <tr>
          <td align="right" class="tabela_titulo">Usu&aacute;rio:</td>
          <td width="270" align="left"><label>
            <input type="hidden" name="codigo_user" <?php if(isset($_POST['codigo_user'])){ echo "value='".$_POST['codigo_user']."'"; } ?> id="codigo_user"  />
            <input type="hidden" name="codigo_unidade" value="<?php echo $_GET['id_uni']; ?>" id="codigo_unidade"  />
            <input name="nome_user"  type="text" <?php if(isset($_POST['nome_user'])){ echo "value='".$_POST['nome_user']."'"; } ?> id="nome_user" size="40" readonly="readonly" style=" font-size:10pt; color: #333333; border: 1px solid #666666; background-color: #FFFFFF; height: 20px; "/>
            <a href="javascript:void(busca());"></a></label>
            <label></label></td>
          <td width="80" align="left"><a href="javascript:void(busca());"><img src="../img/botao.jpg" width="39" height="27" border="0" /></a></td>
          <td align="center">&nbsp;</td>
        </tr>
        <tr>
          <td align="right" class="tabela_titulo">Data Inicio:</td>
          <td align="left"><input name="data_inicio" id="data_inicio"  <?php if(isset($_POST['data_inicio'])){ echo "value='".$_POST['data_inicio']."' "; }else{ echo "value='".date('d/m/Y')."'"; };?> size="15" />&nbsp;<button id="f_btn1">...</button></td>
          <td align="center">&nbsp;</td>
          <td align="center">&nbsp;</td>
        </tr>
        <tr>
          <td align="right" class="tabela_titulo">Data T&eacute;rmino:</td>
          <td align="left"><input name="data_final" id="data_fim"  <?php if(isset($_POST['data_final'])){ echo "value='".$_POST['data_final']."' "; }else{ echo "value='".date('d/m/Y')."'"; };?> size="15" />&nbsp;<button id="f_btn2">...</button></td>
          <td align="center">&nbsp;</td>
          <td align="center">&nbsp;</td>
        </tr>
        <tr>
          <td height="10" colspan="4" align="right" class="tabela_titulo"></td>
          </tr>
        <tr>
          <td width="245" align="right" class="tabela_titulo">&nbsp;</td>
          <td colspan="2" align="right"><input type="submit" name="gerar_log" id="gerar_log" value="Gerar Relat&oacute;rio" /></td>
          <td width="269" align="center">&nbsp;</td>
        </tr>
        <tr>
          <td height="30" colspan="4" align="center">&nbsp;</td>
        </tr>
        
        <?php 
		if(isset($_POST['gerar_log']) and $_POST['codigo_user']!=""){
			
			$data_inicio=$utilidades->data_formato_ingles($_POST['data_inicio']);
			$data_fim=$utilidades->data_formato_ingles($_POST['data_final']);
		?>
        <tr>
          <td height="30" colspan="4" align="center"><table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="28%" align="left"><span class="titulo_cad">Registros Encontrados</span></td>
              <td width="72%" align="center" class="titulo_cad">Data de <?php echo $_POST['data_inicio'] ;?> &agrave; <?php echo $_POST['data_final']; ?></td>
            </tr>
          </table></td>
        </tr>
        <tr>
          <td height="30" colspan="4" align="center"><table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr class="tabela_titulo" >
              <td width="59%" height="25" align="left" valign="middle" bgcolor="#EEEEEE">Hist&oacute;rico</td>
              <td width="21%" height="25" align="center" valign="middle" bgcolor="#EEEEEE">Data e Hora</td>
              <td width="20%" height="25" align="center" valign="middle" bgcolor="#EEEEEE">Terminal</td>
            </tr>
            <?php
			$sql="SELECT historico,date_format(data_hora,'%d/%m/%Y  %H:%i') as data,terminal,data_hora FROM acesso_sistema a where codigo_usuario='".$_POST['codigo_user']."' and data_hora >='".$data_inicio."' and data_hora <='".$data_fim."' ; ";
			//echo $sql;
			  $res=$executar->execSQL($sql);
			  if(mysql_num_rows($res)>0){

			$cont=0;
			  while($dados=mysql_fetch_array($res)){
								  
				  if(($cont%2)==0){
					  $cor="#FFFFCC";
				  }else{
					  $cor="#FFFFFF";
				  }
			?>
            <tr>
              <td height="25" align="left" bgcolor="<?php echo $cor; ?>" valign="middle" class="texto"><?php echo $dados[0]; ?></td>
              <td height="25" align="center" valign="middle" bgcolor="<?php echo $cor; ?>" class="texto"><?php echo $dados[1]; ?></td>
              <td height="25" align="center" valign="middle" bgcolor="<?php echo $cor; ?>" class="texto"><?php echo $dados[2]; ?></td>
            </tr>
            <tr>
              <td height="1" colspan="3" align="center" valign="middle" class="tabela_semana"><span class="titulo_tabela"><img src="../img/linha_.jpg" width="900" height="1" /></span></td>
            </tr>
            <?php
			$cont++;
			  }
			  }else{
			?>
            
            <tr>
              <td height="25" colspan="3" align="center" valign="middle" class="tabela_semana">N&atilde;o h&aacute; Registros.</td>
              </tr>
              <?php
			  }
			  ?>
          </table></td>
        </tr>
        <?php
		}
		if(isset($_POST['gerar_log']) and $_POST['codigo_user']!=""){
		?>
         <tr>
            <td height="25" colspan="4" align="right" valign="middle" ><table width="200" border="0">
              <tr>
                <td height="20" align="center" bgcolor="#333333" class="link"><a href="javascript: imprimir('<?php echo $data_inicio;?>','<?php echo $data_fim;?>','<?php echo $_POST['codigo_user']; ?>','<?php echo $_GET['id_uni']; ?>')" ><span class="link">Vers&atilde;o de Impress&atilde;o</span></a></td>
              </tr>
      </table></td>
              </tr>
              <?php
		}
		?>
      </table></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
    </tr>
  </table>
</form>
<script type="text/javascript">//<![CDATA[
      Calendar.setup({
        inputField : "data_inicio",
        trigger    : "f_btn1",
        onSelect   : function() { this.hide() },
        showTime   : 12,
        dateFormat : "%d/%m/%Y"
      });
	  
	   Calendar.setup({
        inputField : "data_fim",
        trigger    : "f_btn2",
        onSelect   : function() { this.hide() },
        showTime   : 12,
        dateFormat : "%d/%m/%Y"
      });
    //]]></script>
</body>
</html>